package com.job.webSocket.service.impl;

import com.job.client.common.result.AppHttpCode;
import com.job.client.common.result.ResponseResult;
import com.job.webSocket.service.WebSocketService;
import com.job.webSocket.webSocket.WebSocketServer;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashSet;

@Service
public class WebSocketServiceImpl implements WebSocketService {
    @Override
    public ResponseResult pushMessage(String cid, String data) {
        HashSet<String> sids = new HashSet<>();
        sids.add(cid);
        try {
            WebSocketServer.sendMessage(data, sids);
        } catch (IOException e) {
            e.printStackTrace();
            return ResponseResult.ErrorResult(AppHttpCode.WEBSOCKER_ERROR);
        }
        return ResponseResult.OkResult();
    }
}
